<?php
class Videos_model extends Model
{
	function Videos_model()
	{
	parent::Model();
	}
	function getvideocategeories($limit)
	{
		if($limit!=0)
		{
	    $this->db->limit($limit);
		}
		$query = $this->db->get('videos_categeory');
		return $query;
	}
	function getvideos($id,$bywhat)
	{
		$flag=1;
		$query='';
		if($bywhat!='')
		{
			$query.= "where to_Days(sysdate())- to_days(insert_date) >=" .$bywhat." and videouploaded=1 order by name asc";
			$flag=0;
		}
		if($id!=0)
		{
			$query .= 'where video_cat_id ='.$id.' and videouploaded=1 order by name asc';
			$flag=0;
		}
		if($flag!=0)
		{
	    	$query.= " where videouploaded=1";
		$query.=" order by name asc";
		}
		return $query;
	}
	
	function getrecentvideo($limit,$catid,$id)
	{
		$this->db->where('videouploaded',1);
		if($catid!=-1)
		{
			$this->db->where('video_cat_id',$catid);
		}
		if($id!=-1)
		{
			$this->db->where('id !=',$id);
		}
		$this->db->order_by('insert_date','desc');
		if($limit!=0)
		{		$this->db->limit($limit);
		}
		$query = $this->db->get('videos');	
		return $query->result();	
		
	}
	function getvideoname($id)
	{
		$this->db->where('id',$id);
		$this->db->select('name');
		$query = $this->db->get('videos');
		return $query->result();
		
	}
	function gettopviewed($limit)
	{
		$this->db->where('videouploaded',1);
		$this->db->order_by('no_of_views','desc');
		$this->db->limit($limit);
		$query = $this->db->get('videos');	
		return $query;
	}
	function increase_viewcount($id)
	{
		
	    $this->db->query('update videos set no_of_views=no_of_views+1 where id='.$id);
		
	}
	function get_homevideos($id)
	{
		$this->db->where('videouploaded',1);
		$this->db->where('video_cat_id',$id);
		$this->db->limit(5);
		$this->db->order_by('id','desc');
		$query= $this->db->get('videos');
		return $query->result();
	}
	function get_homevideoimage($id)
	{
		$this->db->where('videouploaded',1);
		$this->db->where('video_cat_id',$id);
		$this->db->limit(1);
		$this->db->order_by('id','desc');
		$query= $this->db->get('videos');
		return $query->result();
	}
	

	
}
?>